//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_LOADER_HEADERS_H
#define _UX_LOADER_HEADERS_H

#include "../Textures/Image.h"
#include "../Models/Geometry.h"
#include "../Sounds/SoundSource.h"
#include "../../Systems/FileSys/IFile.h"
#include "../../Systems/Core/CCore.h"

namespace Engine
{
namespace Loaders
{

#define TEXVER	"0.6"	// texture file version
#define MDLVER	"0.7"	// model file version
#define SNDVER	"0.5"	// sound file version
#define FNTVER	"0.5"	// font file version
#define SPRVER	"0.5"	// sprite file version


static const char	s_aTexFileHeader[13] = "TEX "TEXVER" BIN";
static const char	s_aMdlFileHeader[13] = "MDL "MDLVER" BIN";
static const char	s_aSndFileHeader[13] = "SND "SNDVER" BIN";
static const char	s_aSprFileHeader[13] = "SPR "SPRVER" BIN";
static const char	s_aFntFileHeader[13] = "FNT "FNTVER" BIN";


typedef GLenum_t	texformat_t[3];


#pragma pack(push, 1)


	//
	// File Header
	//

	struct TFileHeader
	{
		uint	uHeaderSize,
				uUserDataSize;
	};


	//
	// Font Header
	//
	
	struct TFontHeader
	{
		uint	uCount;
		uint	uUniOffset;
		uint8	uAscOffset;
		///
		TFontHeader(): uCount(0), uUniOffset(0), uAscOffset(0) {}
	};


	//
	// Texture 1D Header
	//

	struct TTexture1DHeader
	{
		uint				uLength;
		uint				uDataSize,
							uMipMapsCount;
		texformat_t			eFormat;
		e_tex_swizzle::type	eSwizzle;
		bool				bCompress;
	};


	//
	// TBO Header
	//

	struct TTBOHeader
	{
		uint				uDataSize;
		texformat_t			eFormat;
	};


	//
	// Texture 2D Header
	//

	struct TTexture2DHeader
	{
		uint				uWidth,
							uHeight;
		uint				uDataSize,
							uMipMapsCount;
		texformat_t			eFormat;
		e_tex_swizzle::type	eSwizzle;
		bool				bCompress;
	};


	//
	// Texture 3D Header
	//

	struct TTexture3DHeader
	{
		uint				uWidth,
							uHeight,
							uDepth;
		uint				uDataSize,
							uMipMapsCount;
		texformat_t			eFormat;
		e_tex_swizzle::type	eSwizzle;
		bool				bCompress;
	};


	//
	// Sprite 2D Header
	//

	struct TSprite2DHeader
	{
		uint		uRectCount,
					uIndicesCount,
					uAnimationsCount;
	};


	//
	// Sprite 2D Animation Header
	//

	struct TSprAnimHeader
	{
		char		aName[32];
		uint		uOffset,
					uCount;
	};


	//
	// Sound Header
	//
	
	struct TSoundHeader
	{
		e_sound_format::type	eSndFormat;
		uint16					uAlFormat;
		uint					uFreq;
		float					fGain,
								fPitch;
		bool					bLooping;
		uint					uBlocksCount;
	};

	
	//
	// Single Mesh Header
	//

	struct TSMeshHeader
	{
		uint		uIndicesSize,
					uVerticesSize;
		uint8		uIdxSize,
					uVertAttribCount;
		GLenum_t	eMode;
		aabb_f		sAABB;
		char		aName[32];
	};


	//
	// Multi Mesh Header
	//

	struct TMultiMeshHeader
	{
		uint		uSubMeshesCount,
					uIndicesSize,
					uVerticesSize,
					uIndicesCount,
					uLODsCount;
	};


	//
	// Sub Mesh Header
	//

	struct TSubMeshHeader
	{
		uint8		uIdxSize,
					uAttribsCount;
		GLenum_t	ePrimitiveMode;
		uint		uIdxCount,
					uIdxOffset;
		aabb_f		sAABB;
		char		aName[32];
	};


	//
	// Sceletal Sub Mesh Header
	//

	struct TScelSubMeshHeader
	{
		uint8		uIdxSize,
					uAttribsCount;
		GLenum_t	ePrimitiveMode;
		uint		uIdxCount,
					uIdxOffset;
	};


	//
	// Sceletal Multi Mesh Header
	//

	struct TScelMultiMeshHeader
	{
		uint		uSubMeshesCount,
					uIndicesSize,
					uVerticesSize,
					uJointsPerFrame,
					uWeightsCount,
					uIndicesCount,
					uLODsCount;
	};


	//
	// Frame Animation Header
	//

	struct TFrameAnimHeader
	{
		float		fFrameRate;
		uint		uTracksCount,
					uFramesCount;
	};


	//
	// Frame Animation Track
	//

	struct TFrameAnimTrack
	{
		char		aName[32];
		uint		uTrackType,
					uFirstFrame,
					uCount;
	};


	//
	// Sceletal Animation Header
	//

	struct TSceletalAnimHeader
	{
		float		fFrameRate;
		uint		uFramesCount,
					uJointPerFrame,
					uTracksCount,
					uBBoxCount;
	};


	//
	// Sceletal Anim Joint Info
	//

	struct TSAJointInfo
	{
		char		aName[32];
		uint		uParent;
		uint		uGroupBits;
	};


	//
	// Sceletal Anim Track Info
	//

	struct TSATrackInfo
	{
		char		aName[32];
		uint		uFirstFrame,
					uFramesCount,
					uGroupMask;
	};


	//
	// Model Header
	//

	struct TModelHeader
	{
		uint		uGeometryOffset,
					uAnimationOffset,
					uMaterialOffset,
					uPhysicsOffset;
	};


#pragma pack(pop)

//-------------------------------------------------------------------

}	// Loaders
}	// Engine

#endif	// _UX_LOADER_HEADERS_H